package com.example.demo.controller;

import com.example.demo.ResponseEntity;
import com.example.demo.utils.FtpFileUtil;
import org.apache.commons.io.FileUtils;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.converter.PicturesManager;
import org.apache.poi.hwpf.converter.WordToHtmlConverter;
import org.apache.poi.hwpf.usermodel.Picture;
import org.apache.poi.hwpf.usermodel.PictureType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.w3c.dom.Document;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.*;
import java.net.URL;
import java.util.List;

/**
 * Created by shuaige on 2019/4/15.
 */
@RestController
public class FtpFileUploadController {

    //ftp处理文件上传
    @PostMapping(value = "/upload")
    public ResponseEntity upload(MultipartFile file) {
        return FtpFileUtil.uploadFile(file);
    }

    //ftp处理文件下载
    @GetMapping("/download")
    public void download(HttpServletResponse response, String pathUrl, @RequestParam(defaultValue = "") String fileName) {
        FtpFileUtil.downloadFile(pathUrl, response, fileName);
    }

    //ftp处理文件删除
    @GetMapping(value = "/delete")
    public ResponseEntity delete(String pathUrl) {
        return FtpFileUtil.deleteFile(pathUrl);
    }

    //预览图片，文本文件及pdf
    @GetMapping("/previewImage")
    public void preview(HttpServletResponse response, String pathUrl) {
        FtpFileUtil.previewImage(response, pathUrl);
    }

    //预览word文档，兼容2003,2007
    @GetMapping("/previewWord")
    public String preview(String pathUrl) {
        return FtpFileUtil.previewWord(pathUrl);
    }
    //预览excel文档，兼容2003,2007
    @GetMapping("/previewExcel")
    public String previewExcel(String pathUrl) {
        return FtpFileUtil.previewExcel(pathUrl);
    }
}

